package vip.meeet.algorithm.str;


public class Num459 {

    public static void main(String[] args) {
        System.out.println(repeatedSubstringPattern("abab"));
        System.out.println(repeatedSubstringPattern("aba"));
        System.out.println(repeatedSubstringPattern("abcabcabcabc"));
        System.out.println(repeatedSubstringPattern("bb"));

    }

    public static boolean repeatedSubstringPattern(String s) {
        int len = s.length();
        int maxLen = len / 2;
        for (int i = 1; i <= maxLen; i++) {
            if (len % i != 0) {
                continue;
            }
            String sub = s.substring(0, i);
            boolean isBreak = false;
            for (int j = i; j < len; j += i) {
                if (!sub.equals(s.substring(j, j + i))) {
                    isBreak = true;
                    break;
                }
            }
            if (!isBreak) {
                return true;
            }
        }
        return false;
    }
}
